Skip to main content

Mac Terminal Cheatsheet

Your friendly guide to mastering the Mac Terminal — because sometimes clicking is just too slow! 🚀

What is Terminal? Terminal is macOS's command-line interface (CLI) that lets you control your Mac using text commands instead of clicking — faster, scriptable, and more powerful.


🧭 Navigation Basics

Getting around your file system is like navigating a building. Your Mac's files are organized in folders (directories), and the terminal lets you walk through them using text commands instead of clicking. Think of pwd as asking "Where am I?", ls as "What's in this room?", and cd as "Take me to...".

CommandWhat It DoesExample
pwdPrint Working Directory — shows your current locationpwd/Users/john/Documents
lsList contents of current directoryls
ls -laList ALL files (including hidden) with detailsls -la
ls -lhList with human-readable file sizesls -lh
cd <folder>Change Directory — move into a foldercd Documents
cd ..Go up one level (parent folder)cd ..
cd ~Go to your home directorycd ~
cd -Go back to previous directorycd -
cd /Go to root directorycd /

💡 Pro Tip: Press Tab to auto-complete folder and file names — saves tons of typing!


📁 File & Folder Operations

Creating, copying, moving, and deleting files is the bread and butter of terminal work. These commands are faster than drag-and-drop once you get the hang of them. Just remember: the terminal doesn't have a trash can — when you rm something, it's gone for good!

CommandWhat It DoesExample
mkdir <name>Make Directory — create a new foldermkdir projects
mkdir -p a/b/cCreate nested folders in one gomkdir -p src/components/ui
touch <file>Create an empty file (or update timestamp)touch notes.txt
cp <src> <dest>Copy a filecp file.txt backup.txt
cp -r <src> <dest>Copy a folder and all its contentscp -r folder1 folder2
mv <src> <dest>Move or rename a file/foldermv old.txt new.txt
rm <file>Remove (delete) a file — no undo!rm unwanted.txt
rm -r <folder>Remove a folder and everything insiderm -r old_project
rm -rf <folder>Force remove without confirmationrm -rf node_modules
rmdir <folder>Remove an empty folder onlyrmdir empty_folder

⚠️ Warning: rm -rf is powerful and dangerous. Double-check your path before hitting Enter!


👀 Viewing File Contents

Sometimes you just need a quick peek inside a file without opening an editor. These commands let you view file contents right in the terminal. Use cat for small files, less for scrolling through big ones, and head/tail when you only need the beginning or end.

CommandWhat It DoesExample
cat <file>Display entire file contentscat readme.md
less <file>View file with scrolling (press q to quit)less long_log.txt
more <file>Similar to less, but simplermore file.txt
head <file>Show first 10 lineshead log.txt
head -n 20 <file>Show first 20 lineshead -n 20 log.txt
tail <file>Show last 10 linestail log.txt
tail -n 50 <file>Show last 50 linestail -n 50 log.txt
tail -f <file>Follow file in real-time (great for logs!)tail -f server.log
wc <file>Word count — lines, words, characterswc essay.txt
wc -l <file>Count lines onlywc -l data.csv

💡 Pro Tip: tail -f is perfect for watching log files update live while debugging!


🔍 Finding Things

Lost a file? Need to find text inside files? These search commands are your detective tools. find searches by file name and location, while grep searches inside files for specific text. Combine them for powerful searches across your entire system.

CommandWhat It DoesExample
find <path> -name "<pattern>"Find files by namefind . -name "*.txt"
find . -type fFind files only (not folders)find . -type f
find . -type dFind directories onlyfind . -type d
find . -mtime -7Files modified in last 7 daysfind . -mtime -7
find . -size +100MFiles larger than 100MBfind . -size +100M
grep "<text>" <file>Search for text in a filegrep "error" log.txt
grep -r "<text>" <dir>Search recursively in directorygrep -r "TODO" src/
grep -i "<text>" <file>Case-insensitive searchgrep -i "hello" file.txt
grep -n "<text>" <file>Show line numbersgrep -n "function" app.js
grep -c "<text>" <file>Count matching linesgrep -c "error" log.txt
mdfind "<query>"Spotlight search from terminalmdfind "budget 2024"
which <command>Find where a command liveswhich python

💡 Pro Tip: Use grep -rn "search" . to search all files and show line numbers — super handy!


✏️ Text Editing in Terminal

Need to edit a file without leaving the terminal? These built-in editors work right in your terminal window. nano is beginner-friendly with on-screen help, while vim is powerful but has a learning curve. For quick edits, nano is your friend!

CommandWhat It DoesExample
nano <file>Open file in Nano editor (beginner-friendly)nano config.txt
vim <file>Open file in Vim editor (powerful but tricky)vim script.sh
vi <file>Same as vim on Macvi file.txt
open <file>Open file with default Mac appopen photo.jpg
open -a "App" <file>Open with specific appopen -a "VS Code" .
open .Open current folder in Finderopen .
pbcopyCopy input to clipboardcat file.txt | pbcopy
pbpastePaste from clipboardpbpaste > newfile.txt

Nano Quick Reference:

  • Ctrl + O → Save file
  • Ctrl + X → Exit
  • Ctrl + K → Cut line
  • Ctrl + U → Paste line

Vim Quick Reference (if you accidentally open it!):

  • Press i → Enter insert mode (to type)
  • Press Esc → Exit insert mode
  • Type :wq → Save and quit
  • Type :q! → Quit without saving

📊 Disk & Storage

Running out of space? Need to know how big a folder is? These commands help you understand what's eating up your disk. df shows overall disk usage, while du digs into specific folders. Perfect for hunting down those mystery files hogging your storage!

CommandWhat It DoesExample
df -hShow disk space usage (human-readable)df -h
du -sh <folder>Show folder sizedu -sh ~/Downloads
du -sh *Show size of all items in current dirdu -sh *
du -h -d 1Show sizes one level deepdu -h -d 1
diskutil listList all disks and partitionsdiskutil list
diskutil info <disk>Show disk informationdiskutil info disk0

💡 Pro Tip: du -sh * | sort -h sorts folders by size — great for finding space hogs!


🔐 Permissions & Ownership

Every file has rules about who can read, write, or run it. Permissions are like locks on doors — they control access. When you see "Permission denied", you might need sudo (superuser do) to override, or chmod to change the rules.

CommandWhat It DoesExample
chmod +x <file>Make file executablechmod +x script.sh
chmod 755 <file>rwx for owner, rx for otherschmod 755 app
chmod 644 <file>rw for owner, r for otherschmod 644 config.txt
chown <user> <file>Change file ownerchown john file.txt
chown -R <user> <dir>Change owner recursivelychown -R john project/
sudo <command>Run as superuser (admin)sudo rm protected.txt
sudo !!Re-run last command as sudosudo !!

Permission Numbers Explained:

  • 7 = read + write + execute (rwx)
  • 6 = read + write (rw-)
  • 5 = read + execute (r-x)
  • 4 = read only (r--)
  • 0 = no permissions (---)

🌐 Networking

Curious about your network connection or need to download something? These commands let you check connectivity, download files, and troubleshoot network issues — all without opening a browser.

CommandWhat It DoesExample
ping <host>Test connection to a serverping google.com
curl <url>Download content from URLcurl https://api.example.com
curl -O <url>Download and save filecurl -O https://example.com/file.zip
wget <url>Download file (if installed)wget https://example.com/file.zip
ifconfigShow network interfacesifconfig
ipconfig getifaddr en0Get your local IP addressipconfig getifaddr en0
networksetup -getinfo Wi-FiGet Wi-Fi network infonetworksetup -getinfo Wi-Fi
lsof -i :<port>Find what's using a portlsof -i :3000
netstat -anShow all network connectionsnetstat -an
traceroute <host>Trace route to hosttraceroute google.com
nslookup <domain>DNS lookupnslookup github.com
ssh <user>@<host>Connect to remote serverssh john@192.168.1.100
scp <file> <user>@<host>:<path>Copy file to remote serverscp file.txt john@server:/home/

💡 Pro Tip: Use curl -I <url> to see just the headers — quick way to check if a site is up!


⚙️ Process Management

Programs running on your Mac are called processes. Sometimes apps freeze or hog resources. These commands let you see what's running, find resource hogs, and kill misbehaving programs — like Task Manager, but cooler!

CommandWhat It DoesExample
ps auxList all running processesps aux
ps aux | grep <name>Find specific processps aux | grep chrome
topLive view of processes (press q to quit)top
htopBetter top (if installed)htop
kill <PID>Terminate process by IDkill 1234
kill -9 <PID>Force kill processkill -9 1234
killall <name>Kill all processes by namekillall Safari
pkill <pattern>Kill processes matching patternpkill -f "node server"
Activity Monitor (GUI)Open via: open -a "Activity Monitor"

💡 Pro Tip: In top, press o then type cpu to sort by CPU usage, or mem for memory!


📦 Package Management (Homebrew)

Homebrew is like an app store for your terminal. It makes installing command-line tools and apps incredibly easy — no more hunting for downloads or dealing with installers. If you don't have it, install it first!

# Install Homebrew (one-time setup)
/bin/bash -c "$(curl -fsSL https://raw.githubusercontent.com/Homebrew/install/HEAD/install.sh)"
CommandWhat It DoesExample
brew install <package>Install a packagebrew install git
brew uninstall <package>Remove a packagebrew uninstall node
brew updateUpdate Homebrew itselfbrew update
brew upgradeUpgrade all packagesbrew upgrade
brew upgrade <package>Upgrade specific packagebrew upgrade python
brew listList installed packagesbrew list
brew search <name>Search for packagesbrew search postgres
brew info <package>Get package informationbrew info node
brew doctorCheck for problemsbrew doctor
brew cleanupRemove old versionsbrew cleanup
brew services listList background servicesbrew services list
brew services start <svc>Start a servicebrew services start postgresql
brew services stop <svc>Stop a servicebrew services stop postgresql
brew install --cask <app>Install GUI appbrew install --cask visual-studio-code

🔧 System Information

Want to know more about your Mac? These commands reveal system details like macOS version, hardware specs, and uptime. Handy for troubleshooting or just satisfying your curiosity!

CommandWhat It DoesExample
sw_versShow macOS versionsw_vers
uname -aSystem informationuname -a
hostnameShow computer namehostname
whoamiShow current usernamewhoami
idShow user and group IDsid
uptimeHow long system has been runninguptime
dateCurrent date and timedate
calShow calendarcal
system_profiler SPHardwareDataTypeHardware overviewsystem_profiler SPHardwareDataType
sysctl -n machdep.cpu.brand_stringCPU modelsysctl -n machdep.cpu.brand_string
top -l 1 | head -n 10Quick system statstop -l 1 | head -n 10

🎯 Handy Shortcuts & Tricks

These tricks will make you feel like a terminal wizard! From keyboard shortcuts to command chaining, these tips speed up your workflow dramatically.

Keyboard Shortcuts

ShortcutWhat It Does
Ctrl + CCancel current command
Ctrl + ZSuspend current process
Ctrl + DLogout / Exit shell
Ctrl + LClear screen (same as clear)
Ctrl + AMove cursor to beginning of line
Ctrl + EMove cursor to end of line
Ctrl + UDelete from cursor to beginning
Ctrl + KDelete from cursor to end
Ctrl + WDelete word before cursor
Ctrl + RSearch command history
TabAuto-complete file/folder names
Tab TabShow all auto-complete options
↑ / ↓Navigate command history
!!Repeat last command
!$Last argument of previous command

Command Chaining

PatternWhat It DoesExample
cmd1 && cmd2Run cmd2 only if cmd1 succeedsnpm install && npm start
cmd1 || cmd2Run cmd2 only if cmd1 failstest -f file || touch file
cmd1 ; cmd2Run both regardless of successecho "Hi" ; echo "Bye"
cmd1 | cmd2Pipe output of cmd1 to cmd2cat file.txt | grep "error"
cmd > fileRedirect output to file (overwrite)ls > files.txt
cmd >> fileRedirect output to file (append)echo "log" >> log.txt
cmd 2>&1Redirect errors to stdoutcommand 2>&1 | tee log.txt

Aliases (Shortcuts You Create)

Add to ~/.zshrc (or ~/.bash_profile for bash):

# Quick navigation
alias ..="cd .."
alias ...="cd ../.."
alias ll="ls -la"
alias la="ls -A"

# Git shortcuts
alias gs="git status"
alias ga="git add ."
alias gc="git commit -m"
alias gp="git push"

# Quick edits
alias zshrc="nano ~/.zshrc"
alias reload="source ~/.zshrc"

# Custom paths
alias projects="cd ~/Projects"
alias downloads="cd ~/Downloads"

After editing, run source ~/.zshrc to apply changes!


📝 Quick Reference Card

# Navigation
pwd # Where am I?
ls -la # What's here?
cd <folder> # Go somewhere
cd .. # Go back

# Files
touch file.txt # Create file
mkdir folder # Create folder
cp src dest # Copy
mv src dest # Move/rename
rm file # Delete (careful!)

# Viewing
cat file # Show contents
less file # Scroll through
head -n 20 file # First 20 lines
tail -f file # Watch live

# Finding
find . -name "*.txt" # Find files
grep "text" file # Search in file
grep -r "text" . # Search all files

# System
top # Monitor processes
kill -9 PID # Kill process
df -h # Disk space
du -sh folder # Folder size

# Homebrew
brew install pkg # Install
brew update && brew upgrade # Update all

Happy terminal-ing! Remember: with great power comes great responsibility... especially with rm -rf! 😄


ResourceDescription
Apple Terminal User GuideOfficial Apple documentation for Terminal
HomebrewThe missing package manager for macOS
Oh My ZshFramework for managing Zsh configuration with themes and plugins
tldr pagesSimplified man pages with practical examples
ExplainShellPaste any command to see what each part does
SS64 macOS CommandsComprehensive A-Z reference of macOS commands
The Art of Command LineMaster the command line in one page
Bash Scripting CheatsheetQuick reference for shell scripting
macOS DefaultsCollection of macOS defaults commands
iTerm2Popular Terminal replacement with extra features

Last updated: February 2026